New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work on easy-configuring of the console execute shortcut. #4054
Work on easy-configuring of the console execute shortcut. #4054
Conversation
@afshin If you are concerned about the amount of time searching the keyboard shortcuts during |
62249fe
to
e824418
Compare
I thought that with #4070 we were able to keep the same structure that currently exists because the line break behavior is correct. Doesn't that obviate the need for checking which shortcut is set? |
No, this is mostly orthogonal: it allows people to choose whether they want to use The fix from #4070 for line breaks works for both keybindings here. |
Right, sorry, I hadn't re-read the code. This seems like a nice feature. I'm a little uncomfortable with the fact that you're writing a setting to another extension's key. Do you think maybe it would be better to update the shortcuts extension to have a public method for saving/overwriting a binding? This seems like behavior other extensions may want even after we create a nice shortcut editor UI, so maybe we should offer it programmatically. What do you think? |
Yes, I agree that it is not ideal to write to the key of a different extension. We could do what you suggest. Another option would be for the |
@ian-r-rose: That's a reasonable solution as long as we make sure the shortcuts extension handles the case where it's the one adding the binding and ignores those! |
I think we can put a change guard somewhere to make that work. |
Yeah, absolutely. I was just pointing it out as a thing to look out for if that's how you want to implement it. I think listening to the |
Sure, I'll do that here. |
Awesome. |
Hmm, this is actually a bit trickier than I had hoped. I am not sure how to remove an existing keybinding in an extension without a handle on the |
I haven't tested this! But something like this logic should do it, I think. diff --git a/packages/shortcuts-extension/src/index.ts b/packages/shortcuts-extension/src/index.ts
index f4819054d..0f933f533 100644
--- a/packages/shortcuts-extension/src/index.ts
+++ b/packages/shortcuts-extension/src/index.ts
@@ -14,7 +14,7 @@ import {
} from '@phosphor/commands';
import {
- JSONObject, JSONValue
+ JSONExt, JSONObject, JSONValue
} from '@phosphor/coreutils';
import {
@@ -57,7 +57,25 @@ const plugin: JupyterLabPlugin<void> = {
const { commands } = app;
settingReqistry.load(plugin.id).then(settings => {
+ // Load the shortcuts on initial load.
Private.loadShortcuts(commands, settings.composite);
+
+ // Save newly modified key bindings to settings.
+ commands.keyBindingChanged.connect((sender: any, change: CommandRegistry.IKeyBindingChangedArgs) => {
+ const { args, command, keys, selector } = change.binding;
+ const binding = {
+ command, selector,
+ args: args as JSONObject,
+ keys: keys as Array<string>
+ };
+ const key = Object.keys(settings.composite).filter(key => {
+ return JSONExt.deepEqual(binding, settings.composite[key]);
+ })[0] || command;
+
+ settingReqistry.set(plugin.id, key, binding);
+ });
+
+ // Reload the shortcuts if settings change.
settings.changed.connect(() => {
Private.loadShortcuts(commands, settings.composite);
}); |
Oh wait, I once again misunderstood your question. You're saying you can't remove an extant binding. Right. It might be the case that offering a save method in the shortcuts extension is the way to go after all. |
And possibly also listening to the |
Right, only the owner of the keybinding seems to be able to remove it. I suppose we should go with some sort of |
Taking another look at this: I think we need a better story for best practices when it comes to keyboard shortcuts. Currently the
Anyways, food for thought. I am not sure what the best way forwards is. |
const enterToExecute = 'console:enter-to-execute'; | ||
|
||
export | ||
const shiftEnterToExecute = 'consol:shift-enter-to-execute'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consol
maybe should be console
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, right you are.
e824418
to
33b20d6
Compare
According to @ian-r-rose this needs a rebase and then review/merge. |
33b20d6
to
ce6ab99
Compare
@afshin This is rebased and ready for a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ian-r-rose!
Fixes #3643.
This makes the keyboard stroke to execute a console cell more easily configurable. It allows easy toggling/setting of
Enter
vsShift-Enter
to execute. Other shortcuts may still be set using the Settings Editor if the user desires.